package com.dxyxx.framework;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.dxyxx.R;
import com.dxyxx.utils.BarcodeCreater;

public class CommonBarcodeActivity extends BaseActivity {
	private int width;
	private ImageView refreshImage;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_scan);
		findViewById(R.id.backImageButton).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				finish();

			}
		});

		refreshImage = (ImageView) findViewById(R.id.nextImageButton);
		refreshImage.setVisibility(View.INVISIBLE);

		TextView titleView = (TextView) findViewById(R.id.title);
		titleView.setText("提货券扫描");
		titleView.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);

		TextView networkWord = (TextView) findViewById(R.id.networkWord);
		String code = getIntent().getStringExtra("code");
		networkWord.setText(code);
		// 得到屏幕宽度。
		WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
		width = wm.getDefaultDisplay().getWidth();// 用来匹配生成 条形码的 宽度

		createImgage(code);

	}

	private void createImgage(String content) {
		// String content = "az1520196726723";
		Bitmap bitmap = null;
		ImageView iv = (ImageView) findViewById(R.id.scanResult);
		bitmap = BarcodeCreater.creatBarcode(getApplicationContext(), content, width - 40, (width - 40) / 2, false);
		// Drawable drawable = new BitmapDrawable(bitmap);
		iv.setImageBitmap(bitmap);
		// iv.setImageDrawable(drawable);;
	}

}
